package frog.lazy.framework.core.tools;

import cn.hutool.cache.CacheUtil;
import cn.hutool.cache.impl.TimedCache;
import cn.hutool.core.date.DateUnit;

public class CacheUtils extends CacheUtil {
    // 缓存时间
    private static final Integer CACHE_TIME = 5;
    private static final TimedCache<String, Object> timedCache = CacheUtil.newTimedCache(DateUnit.MINUTE.getMillis() * CACHE_TIME);
    static {
        timedCache.schedulePrune(DateUnit.SECOND.getMillis() * 1);
    }

    public static void put(String key, Object value) {
        timedCache.put(key, value);
    }

    public static void put(String key, Object value,long timeout) {
        timedCache.put(key, value, timeout);
    }

    public static Object get(String key) {
        Object obj = timedCache.get(key);
        put(key, obj);
        return timedCache.get(key);
    }

    public static void remove(String key){
        timedCache.remove(key);
    }

}
